package cn.conow.pmo.service;

import cn.conow.pmo.dao.PersonDao;
import cn.conow.pmo.entity.Person;
import cn.conow.system.util.*;
import cn.conow.system.web.ServletUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;

/**
 * Person服务实现类
 * @author dapaer
 * @since v1.0.0
 */
@Service
public class PersonServiceImpl implements PersonService {

	@Autowired
	private PersonDao personDao;


	private void configOther(Person... persons){
		Date curDate = new Date();
		String creater = ServletUtil.getSessionCurrentUser().getID();
		for (Person person : persons) {
			if(StringUtil.isEmpty(person.getID())){
				person.setCREATE_TIME(curDate);
				person.setCREATER(creater);
				person.setCORP_ORG_ID(ServletUtil.getCurrentCorpOrgId());
			}
			person.setUPDATE_TIME(curDate);
			person.setUPDATER(creater);
		}
	}

	@Override
	public void saveOrUpdate(Person...persons) {
		for (Person person: persons){
			if (StringUtil.isEmpty(person.getID())) {
				this.saveEntity(person);
			} else {
				this.updateEntity(person);
			}
		}
	}


	@Override
	public void saveEntity(Person... person) {
		this.configOther(person);
		personDao.save(person);
	}

	@Override
	public void updateEntity(Person... person) {
		this.configOther(person);
		personDao.update(person);
	}

	@Override
	public List<Person> queryByParams(Person person) {
		return personDao.queryByParams(person);
	}

	@Override
	public List<Map> queryMapByParams(Person person) {
		return personDao.queryMapByParams(person);
	}

	@Override
	public List<Map> queryPageByParams(Person person) {
		return personDao.queryPageByParams(person);
	}

	@Override
	public Map queryById(String id) {
		return prjAnnualObjDao.queryById(id);
	}

}
